package com.excilys.ymca.util;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

@Singleton
public class LoggedInHttpClientProvider implements Provider<HttpClient> {

    @Inject
    private SessionCookieHolder sessionCookieHolder;

    @Override
    public HttpClient get() {

        DefaultHttpClient httpClient = new DefaultHttpClient();

        httpClient.getCookieStore().addCookie(sessionCookieHolder.getSessionCookie());

        return httpClient;
    }

}
